// pages/team/income/income.js
var util = require('../../../utils/util.js');
var api = require('../../../config/api.js');
Page({
  /**
   * 页面的初始数据
   */
  data: {
      is_w:2,
      popupView:false,
      number:0,
      revenueInfo:{
        cumulativeIncome:0,
        isWithdrawal: 0,
        invalidIncome: 0,
        unsettledIncome: 0,
        appForIncome: 0,
        isNoPaymentIncome: 0,
        successWithdrawalIncome: 0,
        toBeReceivedIncome: 0,
        notice: "买家确认收货之后，立即获得收益注意:可用收益满 20元 后才能申请提现"
    },
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
      this.getspreaderRevenueDetails();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },
  getspreaderRevenueDetails() {
    let that = this;
    let userId = wx.getStorageSync("userId");
    util.request(api.spreaderRevenueDetails, {
      userId:userId,
    }).then(function(res) {
      // console.log(res);return false;
      if (res.errno === 0) {
        that.setData({
          revenueInfo : res.data,
        })
      }
    });
  },
  withdrawal(){
    this.setData({popupView:true})
  },
  hideCover(){
    this.setData({
      popupView: false
    })
  },
  changePopupView(){
    this.setData({popupView:!this.data.popupView})
},
bindKeyInput(e){
  this.setData({
    number:e.detail.value,
  });
},
ok(){
  let that = this;
  var regex = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/;
  if (!regex.test(that.data.number)) {
    // 如果不是数字，可以给出提示或者执行其他操作
    wx.showToast({
      title: '请输入有效的金额',
      icon: 'none'
    });
  } 
  if(that.data.number == 0){
    wx.showToast({
      title: '请输入金额',
      icon: 'none'
    });
     return false;
  }
  // if(that.data.number < 20){
  //   wx.showToast({
  //     title: '最低提现金额20',
  //     icon:"none",
  //   })
  //   return false;
  // }
  //请求接口
  util.request(api.spreaderMoney, {
    userId: wx.getStorageSync("userId"),
    money:that.data.number,
  }).then(function(res) {
    if (res.errno == 0) {
        wx.showToast({
          title: '提交成功',
        });
        that.setData({popupView:false})
    }else{
      util.showErrorToast(res.errmsg);
    }
  });

},
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})